package org.zxl.app;

import org.zxl.api.SpiDemoService;
import org.zxl.api.platform.service.PlatformService;
import org.zxl.api.vm.service.VmService;
import org.zxl.app.manage.ProviderManage;

import java.util.Scanner;

public class CloudSureApplication {
    public static void main(String[] args) {
        System.out.println("start");
        ProviderManage.register();

        System.out.println("**************************服务注册完成******************************************");
        String type = "";

        Scanner scanner = new Scanner(System.in);
        while (!type.equals("exit")){
            System.out.println("请输入服务类型，1:SpiDemoService；2:PlatformService；3:VmService。退出请输入exit。");
            type = scanner.nextLine();
            switch (type){
                case "1":
                    SpiDemoServiceTest();
                    break;
                case "2":
                    platformServiceTest();
                    break;
                case "3":
                    vmServiceTest();
                    break;
                default:
                    System.out.println("没有找到对应的类型");
                    break;
            }

        }

        System.out.println("end!");
    }

    public static void SpiDemoServiceTest() {
        System.out.println("vmService 测试");
        String nameVersion = "";
        Scanner scanner = new Scanner(System.in);
        while (!nameVersion.equals("exit")){
            ProviderManage.printSpiDemoServiceVersion();
            System.out.println("请输入服务名称和版本号，格式为：服务名称_版本号。退出请输入exit。");
            nameVersion = scanner.nextLine();

            SpiDemoService spiDemoService = ProviderManage.getSpiDemoService(nameVersion);
            if(spiDemoService != null){
                System.out.println(spiDemoService.sayHello());
            }else {
                System.out.println("没有找到对应的服务");
            }
            System.out.println("********************************************************************");
        }
    }

    public static void platformServiceTest() {
        System.out.println("platformService 测试");
        String nameVersion = "";
        Scanner scanner = new Scanner(System.in);
        while (!nameVersion.equals("exit")){
            ProviderManage.printPlatformServiceVersion();
            System.out.println("请输入服务名称和版本号，格式为：服务名称_版本号；退出请输入exit。");
            nameVersion = scanner.nextLine();

            PlatformService platformService = ProviderManage.getPlatformService(nameVersion);
            if(platformService != null){
                System.out.println(platformService.login(null));
            }else {
                System.out.println("没有找到对应的服务");
            }
            System.out.println("********************************************************************");
        }
    }
    public static void vmServiceTest() {
        System.out.println("vmService 测试");
        String nameVersion = "";
        Scanner scanner = new Scanner(System.in);
        while (!nameVersion.equals("exit")){
            ProviderManage.printVmServiceVersion();
            System.out.println("请输入服务名称和版本号，格式为：服务名称_版本号；退出请输入exit。");
            nameVersion = scanner.nextLine();

            VmService vmService = ProviderManage.getVmService(nameVersion);
            if(vmService != null){
                System.out.println(vmService.listAllReal());
            }else {
                System.out.println("没有找到对应的服务");
            }
            System.out.println("********************************************************************");
        }
    }
}